﻿@model BannerModel

<style type="text/css">
    .laytable-cell-1-PictureUrl {
        height: 100%;
        max-width: 100%;
    }
    .layui-table img {
        max-width: 160px;
    }
    .layui-table-view .layui-table td {
        padding: 0px;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-normal layuiadmin-btn-tags" data-type="add">添加</button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-banner-list" lay-data="" lay-filter="LAY-banner-list"></table>
            <script type="text/html" id="layuiadmin-app-cont-tagsbar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script>
    layui.use(['index','table','form'], function () {
        var table = layui.table
            ,form = layui.form;
        //分类管理
        table.render({
            elem: '#LAY-banner-list'
            , method: 'post'
            , id:'resource-list'
            , url: '@Html.Raw(Url.Action("BannerItem", "Banner",new { id=ViewBag.BannerId }))' //模拟接口
            , page: true //开启分页
            , even: true
            , limit: 30
            , limits: [15, 30, 50, 100]
            , cols: [[
                { type: 'numbers', fixed: 'left', style: 'height:130px;'  }
                , { field: 'PictureUrl', width: 160, style: 'height:120px;', title: '图片', templet: '<div><img height=120 src={{d.PictureUrl}}></div>' }
                , { field: 'Title', title: '标题', minWidth: 100, style: 'height:130px;'  }
                , { field: 'SubTitle', title: '副标题', minWidth: 100, style: 'height:130px;'  }
                , { field: 'DisplayOrder', title: '顺序', minWidth: 100, style: 'height:130px;'  }
                , { title: '操作', width: 220, align: 'center', fixed: 'right', toolbar: '#layuiadmin-app-cont-tagsbar', style: 'height:130px;'  }
            ]]
            , text: { none: '一条数据也没有^_^' }
        });

        //监听工具条
        table.on('tool(LAY-banner-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除？', function (index) {
                    obj.del();
                    $.post('@Url.Action("ItemDelete")', { id: obj.data.Id });
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: '@Url.Action("ItemUpdate")?id=' + data.Id + '&zoneId=' +@ViewBag.BannerId
                    , shade: 0.2
                    , maxmin: true
                    , shadeClose: true
                    , area: ['500px', '560px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        
                        var submit = layero.find('iframe').contents().find("#set_system_submit_btn");
                        submit.click();
                    }
                });
            }
        });
        //监听单元格编辑
        table.on('edit(LAY-banner-list)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            $.post('@Url.Action("ItemUpdate")', { id: data.Id,name:obj.data.Name,value:obj.data.Value});
        });
        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('resource-list', {
                url:'@Html.Raw(Url.Action("List", "Banner"))'
                ,where: field
            });
        });
        var $ = layui.$, active = {
            add: function () {
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: '@Url.Action("ItemUpdate")?zoneId=@ViewBag.BannerId'
                    , shade: 0.2
                    , maxmin: true
                    , shadeClose: true
                    , area: ['600px', '400px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        
                        var submit = layero.find('iframe').contents().find("#set_system_submit_btn");
                        submit.click();
                    }
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
